import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/models/userInfoModel.dart';

class WxShare extends StatelessWidget {
  /// 分享的标题
  final String title;

  /// 分享的图片
  final String pic;

  /// 分享类型
  final WeChatScene scene;

  /// 子组件
  final Widget child;

  const WxShare({
    this.title = '探果直播',
    this.pic,
    @required this.child,
    this.scene = WeChatScene.SESSION,
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () async {
        if (await isWeChatInstalled) {
          UserInfoModel info = (state(context, 'user').info as UserInfoModel);
          shareToWeChat(
            WeChatShareWebPageModel(
              Config.WECHAT_SHARE_URL + '?share=' + info.invitationcode,
              title: '$title',
              description: '$title',
              thumbnail: pic == null
                  ? WeChatImage.asset('assets/images/icon/logo.png')
                  : WeChatImage.network('$pic'),
              scene: scene,
            ),
          );
        } else {
          showToast('我们检测到你还没有安装微信');
        }
      },
      child: child,
    );
  }
}
